package com.ruoyi.baselibrary.infotargetsystem.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.baselibrary.infotargetsystem.domain.InfoTargetSystem;
import com.ruoyi.baselibrary.infotargetsystem.service.IInfoTargetSystemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 指标体系Controller
 *
 * @author ruoyi
 * @date 2022-02-08
 */
@RestController
@RequestMapping("/infoTargetSystem/infoTargetSystem")
public class InfoTargetSystemController extends BaseController {
    @Autowired
    private IInfoTargetSystemService infoTargetSystemService;

    /**
     * 查询指标体系列表
     */
    @PreAuthorize("@ss.hasPermi('infoTargetSystem:infoTargetSystem:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoTargetSystem infoTargetSystem) {
        startPage();
        List<InfoTargetSystem> list = infoTargetSystemService.selectInfoTargetSystemList(infoTargetSystem);
        return getDataTable(list);
    }

    /**
     * 导出指标体系列表
     */
    @PreAuthorize("@ss.hasPermi('infoTargetSystem:infoTargetSystem:export')")
    @Log(title = "指标体系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoTargetSystem infoTargetSystem) {
        List<InfoTargetSystem> list = infoTargetSystemService.selectInfoTargetSystemList(infoTargetSystem);
        ExcelUtil<InfoTargetSystem> util = new ExcelUtil<InfoTargetSystem>(InfoTargetSystem.class);
        util.exportExcel(response, list, "指标体系数据");
    }

    /**
     * 获取指标体系详细信息
     */
    @PreAuthorize("@ss.hasPermi('infoTargetSystem:infoTargetSystem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoTargetSystemService.selectInfoTargetSystemById(id));
    }

    /**
     * 新增指标体系
     */
    @PreAuthorize("@ss.hasPermi('infoTargetSystem:infoTargetSystem:add')")
    @Log(title = "指标体系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoTargetSystem infoTargetSystem) {
        return toAjax(infoTargetSystemService.insertInfoTargetSystem(infoTargetSystem));
    }

    /**
     * 修改指标体系
     */
    @PreAuthorize("@ss.hasPermi('infoTargetSystem:infoTargetSystem:edit')")
    @Log(title = "指标体系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoTargetSystem infoTargetSystem) {
        return toAjax(infoTargetSystemService.updateInfoTargetSystem(infoTargetSystem));
    }

    /**
     * 删除指标体系
     */
    @PreAuthorize("@ss.hasPermi('infoTargetSystem:infoTargetSystem:remove')")
    @Log(title = "指标体系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoTargetSystemService.deleteInfoTargetSystemByIds(ids));
    }

    /**
     * 不分页查询指标体系
     *
     * @return
     */
    @RequestMapping(value = "/noPageList", method = RequestMethod.GET)
    public AjaxResult noPageList() {
        List<InfoTargetSystem> infoTargetSystems = infoTargetSystemService.selectInfoTargetSystemList(new InfoTargetSystem());
        return AjaxResult.success(infoTargetSystems);
    }
}
